﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using ExpressionEvaluator.Expceptions;

namespace ExpressionEvaluator.BuilderTreeNode
{
	internal class NotNode : BuilderTreeNodeBase
	{
		public override Expression GetExpression(BuilderTree tree)
		{
			if (Nodes.Count == 1)
			{
				return Expression.Not(Nodes[0].GetExpression(tree));
			}
			throw new EvalException(string.Format("Negator should have only one parameter! But you set '{0}'!", Nodes.Count), Idents[0]);
		}

		public override string ToString()
		{
			if (Nodes.Count == 1)
			{
				return string.Format("!({0})", Nodes[0].ToString());
			}
			return "!(ERROR)";
		}
	}
}
